package com.lyj.service.impl;

import com.lyj.mapper.UserMapper;
import com.lyj.pojo.User;
import com.lyj.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(String loginName, String password) {
        User user = userMapper.findUserByLoginName(loginName);
        if (user != null){
            if (user.getPassword().equals(password)){
                return user;
            }
            return null;
        }
        return null;
    }

    @Override
    public User findUserByLoginName(String loginName) {
        return userMapper.findUserByLoginName(loginName);
    }

    @Override
    public void addUser(User user) {
        userMapper.insertUser(user);
    }

    @Override
    public List<User> findAllUser(User user) {
        return userMapper.findAllUser(user);

    }

    @Override
    public User findUserById(Integer id) {
        return userMapper.findUserById(id);
    }

    @Override
    public void deleteById(Integer id) {
        userMapper.deleteById(id);
    }

    @Override
    public void updateById(User user) {
        userMapper.updateById(user);
    }

    @Override
    public void auditUserByIds(Integer[] ids) {
        for (Integer id : ids) {
            userMapper.auditUserById(id);
        }
    }

    @Override
    public void updatePasswordById(User user) {
        userMapper.updatePasswordById(user);
    }

    @Override
    public void updateAvatarById(Integer id, String avatar) {
        User user = new User();
        user.setId(id);
        user.setAvatar(avatar);
        userMapper.updateAvatarById(user);
    }

    @Override
    public List<String> findAllAvatar() {

        return userMapper.findAllAvatar();
    }

}
